package com.cskaoyan.market.aspect;


import com.cskaoyan.market.util.ValidationUtil;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.validation.BindingResult;

/**
 * @author: YaLiFeng
 * @description: TODO
 * @date: 2024/5/20 23:12
 */
@Component
@Aspect
public class ValiadationAspect {
    @Pointcut("@annotation(com.cskaoyan.market.annotation.ValidParam))")
    public void pt(){

    }
    @Before("pt()")
    public void valied(JoinPoint joinPoint){
        Object[] args=joinPoint.getArgs();
        for(Object arg:args){
            if(arg instanceof BindingResult){
                ValidationUtil.validate((BindingResult) arg);
            }
        }
    }
}
